//
//  LCZTableHeadViewController.m
//  PersonalNews
//
//  Created by Golibyo on 15/11/27.
//  Copyright © 2015年 changshuhua. All rights reserved.
//

#import "LCZTableHeadViewController.h"
#import "LCZTableHeadCell.h"
#import "LCZFMDetailViewController.h"
@interface LCZTableHeadViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, strong)LCZBaseTableView *tableView;

@property(nonatomic, strong)NSMutableArray *myArr;

@end

@implementation LCZTableHeadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    NSLog(@"%@", self.cid);
    [self createView];
    [self createData];
    // Do any additional setup after loading the view.
}

- (void)createView {
    self.tableView = [[LCZBaseTableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerClass:[LCZTableHeadCell class] forCellReuseIdentifier:@"reuse"];
    self.tableView.rowHeight = HEIGHT / 667.0 * 100;
    [self.view addSubview:self.tableView];
    
}

- (void)createData {
    NSString *URL = [NSString stringWithFormat:@"http://c.m.163.com/nc/topicset/android/radio/%@/0-20.html", self.cid];
    [LCZNetWorkTools getdataWithString:URL block:^(id block) {
        self.myArr = [NSMutableArray array];
        NSDictionary *dic = block;
        self.myArr = dic[@"tList"];
        [self.tableView reloadData];
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.myArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LCZTableHeadCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath];
    cell.titleLabel.text = self.myArr[indexPath.row][@"tname"];
    [cell.myImageView sd_setImageWithURL:[NSURL URLWithString:self.myArr[indexPath.row][@"radio"][@"imgsrc"]]];
    cell.timeLabel.text = [NSString stringWithFormat:@"%.1f万", [self.myArr[indexPath.row][@"playCount"] floatValue] / 10000.0];
    cell.detailLabel.text = self.myArr[indexPath.row][@"radio"][@"title"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    LCZFMDetailViewController *fmVC = [[LCZFMDetailViewController alloc] init];
    [self.navigationController pushViewController:fmVC animated:YES];
    fmVC.arr = self.myArr;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
